import java.util.Scanner;

public class Main2 {

    public static long num = (long) Math.pow(2, 64);

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        while (t > 0) {
            t--;

            int n = sc.nextInt();
            int m = sc.nextInt();
            int q = sc.nextInt(); //询问次数

            long[][] arr = new long[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    arr[i][j] = sc.nextLong();
                }
            }

            long[][] dp = new long[n + 1][m + 1]; //创建前缀和数组
            for (int i = 1; i < n + 1; i++) {
                for (int j = 1; j < m + 1; j++) {
                    dp[i][j] = arr[i - 1][j - 1] + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
                }
            }

            long ret = 0;
            while (q > 0) {
                q--;
                int u = sc.nextInt();
                int v = sc.nextInt();
                int x = sc.nextInt();
                int y = sc.nextInt();

                long sum = dp[x][y] - dp[x][v - 1] - dp[u - 1][y] + dp[u - 1][v - 1];
                ret ^= sum;
            }
            System.out.println(ret % num);
        }

        sc.close();
    }
}
